%%This file can draw pdr bargraph for small network and large network with different traffic load.
%% light traffic and heavy traffic
clc
close all
clear all

%the file @pdr_samples.mat should contain the following column vectors
% pdr_prks70, pdr_prks80, pdr_prks90, pdr_prks95
% pdr_cmac70, pdr_cmac80, pdr_cmac90, pdr_cmac95
% pdr_rid70, pdr_rid80, pdr_rid90, pdr_rid95
% pdr_scream, pdr_csma, pdr_rtscts
%
%
load pdr_samples.mat
ALPHA=0.05;

pdr_prks70 = 100 * pdr_prks70;
pdr_prks80 = 100 * pdr_prks80;
pdr_prks90 = 100 * pdr_prks90;
pdr_prks95 = 100 * pdr_prks95;
pdr_cmac70 = 100 * pdr_cmac70;
pdr_cmac80 = 100 * pdr_cmac80;
pdr_cmac90 = 100 * pdr_cmac90;
pdr_cmac95 = 100 * pdr_cmac95;
pdr_rid70 = 100 * pdr_rid70;
pdr_rid80 = 100 * pdr_rid80;
pdr_rid90 = 100 * pdr_rid90;
pdr_rid95 = 100 * pdr_rid95;
pdr_csma = 100 * pdr_csma;
pdr_rtscts = 100 * pdr_rtscts;
pdr_scream = 100 * pdr_scream;

MEAN = zeros(4,6);
Error_MEAN = zeros(4,6);
MEAN(1,1) = mean(pdr_prks70);
MEAN(1,2) = mean(pdr_csma);
MEAN(1,3) = mean(pdr_rtscts);
MEAN(1,4) = mean(pdr_rid70);
MEAN(1,5) = mean(pdr_cmac70);
MEAN(1,6) = mean(pdr_scream);
Error_MEAN(1,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_prks70) / sqrt(size(pdr_prks70, 1));
Error_MEAN(1,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_csma) / sqrt(size(pdr_csma, 1));
Error_MEAN(1,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_rtscts) / sqrt(size(pdr_rtscts, 1));
Error_MEAN(1,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_rid70) / sqrt(size(pdr_rid70, 1));
Error_MEAN(1,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_cmac70) / sqrt(size(pdr_cmac70, 1));
Error_MEAN(1,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_scream) / sqrt(size(pdr_scream, 1));

MEAN(2,1) = mean(pdr_prks80);
MEAN(2,2) = mean(pdr_csma);
MEAN(2,3) = mean(pdr_rtscts);
MEAN(2,4) = mean(pdr_rid80);
MEAN(2,5) = mean(pdr_cmac80);
MEAN(2,6) = mean(pdr_scream);
Error_MEAN(2,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_prks80) / sqrt(size(pdr_prks80, 1));
Error_MEAN(2,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_csma) / sqrt(size(pdr_csma, 1));
Error_MEAN(2,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_rtscts) / sqrt(size(pdr_rtscts, 1));
Error_MEAN(2,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_rid80) / sqrt(size(pdr_rid80, 1));
Error_MEAN(2,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_cmac80) / sqrt(size(pdr_cmac80, 1));
Error_MEAN(2,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_scream) / sqrt(size(pdr_scream, 1));

MEAN(3,1) = mean(pdr_prks90);
MEAN(3,2) = mean(pdr_csma);
MEAN(3,3) = mean(pdr_rtscts);
MEAN(3,4) = mean(pdr_rid90);
MEAN(3,5) = mean(pdr_cmac90);
MEAN(3,6) = mean(pdr_scream);
Error_MEAN(3,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_prks90) / sqrt(size(pdr_prks90, 1));
Error_MEAN(3,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_csma) / sqrt(size(pdr_csma, 1));
Error_MEAN(3,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_rtscts) / sqrt(size(pdr_rtscts, 1));
Error_MEAN(3,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_rid90) / sqrt(size(pdr_rid90, 1));
Error_MEAN(3,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_cmac90) / sqrt(size(pdr_cmac90, 1));
Error_MEAN(3,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_scream) / sqrt(size(pdr_scream, 1));

MEAN(4,1) = mean(pdr_prks95);
MEAN(4,2) = mean(pdr_csma);
MEAN(4,3) = mean(pdr_rtscts);
MEAN(4,4) = mean(pdr_rid95);
MEAN(4,5) = mean(pdr_cmac95);
MEAN(4,6) = mean(pdr_scream);
Error_MEAN(4,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_prks95) / sqrt(size(pdr_prks95, 1));
Error_MEAN(4,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_csma) / sqrt(size(pdr_csma, 1));
Error_MEAN(4,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_rtscts) / sqrt(size(pdr_rtscts, 1));
Error_MEAN(4,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_rid95) / sqrt(size(pdr_rid95, 1));
Error_MEAN(4,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_cmac95) / sqrt(size(pdr_cmac95, 1));
Error_MEAN(4,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(pdr_scream) / sqrt(size(pdr_scream, 1));

figure;
handle = barweb(MEAN, Error_MEAN,1, ['70';'80';'90';'95'], [], ['PDR requirement(%)'], ['Mean PDR(%)'], jet);
handle.legend =legend ('PRKS','CSMA','RTS-CTS', 'RIDB','CMAC','SCREAM','orientation','horizontal');
set(gca,'fontsize',20);
box on
maximize ();
saveas (gcf,'temp.fig');

%[im_hatch, colorlist]=applyhatch_pluscolor(gcf, '/-\xkc',1,[1 1 1 1 0 1],[],[],5,10);
